Skip to content

Move Python starter template to TypeScript AppHost and CLI template factory#15574

Open
davidfowl wants to merge 1 commit intomainfrom
davidfowl/python-template-ts
Open

Move Python starter template to TypeScript AppHost and CLI template factory#15574
davidfowl wants to merge 1 commit intomainfrom
davidfowl/python-template-ts

Conversation

@davidfowl
Copy link
Contributor

@davidfowl davidfowl commented Mar 25, 2026

Description

Migrates the aspire-py-starter template from the old dotnet new template system (DotNetTemplateFactory with C# AppHost) to the new embedded CLI template system (CliTemplateFactory with TypeScript AppHost).

Motivation: Narrowing down the toolchains required — by moving to a TypeScript AppHost, the Python starter no longer requires the .NET SDK/C# toolchain for the AppHost project, aligning it with the same pattern as aspire-ts-starter.

What changed

  • New embedded template at src/Aspire.Cli/Templating/Templates/py-starter/ with a TypeScript AppHost using addUvicornApp, conditional Redis support via {{#redis}}/{{/redis}} block markers, and a Vite React frontend
  • New CliTemplateFactory.PythonStarterTemplate.cs — factory logic for the Python starter, including Redis conditional processing and aspire.config.json package injection
  • New ConditionalBlockProcessor utility class — extracted reusable conditional block processing with 29 unit tests covering comment styles, edge cases, multiple conditions, and realistic template scenarios
  • Removed old template from Aspire.ProjectTemplates (dotnet new aspire-py-starter is replaced by aspire new aspire-py-starter)
  • Updated registrationsaspire-py-starter moved from DotNetTemplateFactory to CliTemplateFactory with --use-redis-cache and --localhost-tld options
  • Updated testsDotNetTemplateFactoryTests updated to expect py-starter not in dotnet templates; hostname tests removed for py-starter

Validation

  • Build succeeds (both Aspire.Cli and Aspire.ProjectTemplates)
  • 29 ConditionalBlockProcessorTests pass
  • 12 DotNetTemplateFactoryTests pass
  • 27 NewCommandTests pass (confirms aspire-py-starter listed in CLI help)
  • E2E tested: aspire new aspire-py-starter generates correct output for both --use-redis-cache false and --use-redis-cache true variants

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
    • No
  • Does the change require an update in our Aspire docs?

Copilot AI review requested due to automatic review settings March 25, 2026 07:06
@github-actions
Copy link
Contributor

github-actions bot commented Mar 25, 2026

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 15574

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 15574"

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Migrates the Python starter template (aspire-py-starter) from the legacy dotnet new template pipeline to the embedded CLI template pipeline, switching the AppHost from C# to TypeScript to reduce required toolchains and align with the existing TS starter pattern.

Changes:

  • Removed aspire-py-starter from DotNetTemplateFactory / old project template assets and updated tests accordingly.
  • Added a new embedded CLI template tree for py-starter (TypeScript AppHost + FastAPI backend + Vite React frontend).
  • Introduced ConditionalBlockProcessor (with unit tests) and added a new CLI template factory implementation for the Python starter, including a --use-redis-cache option and conditional template processing.

Reviewed changes

Copilot reviewed 36 out of 57 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/Aspire.Templates.Tests/LocalhostTldHostnameTests.cs Removes py-starter coverage from dotnet-template hostname tests since it’s no longer a dotnet template.
tests/Aspire.Cli.Tests/Templating/DotNetTemplateFactoryTests.cs Updates expectations so py-starter is no longer returned by DotNetTemplateFactory.
tests/Aspire.Cli.Tests/Templating/ConditionalBlockProcessorTests.cs Adds unit coverage for the new conditional block processing utility.
src/Aspire.ProjectTemplates/Aspire.ProjectTemplates.csproj Stops packaging the old py-starter dotnet template content.
src/Aspire.Cli/Aspire.Cli.csproj Embeds the new py-starter template resources into the CLI.
src/Aspire.Cli/Templating/DotNetTemplateFactory.cs Removes py-starter from dotnet template enumeration and associated prompt logic.
src/Aspire.Cli/Templating/KnownTemplateId.cs Adds a PythonStarter known template ID constant.
src/Aspire.Cli/Templating/ConditionalBlockProcessor.cs Adds reusable conditional block marker processing for templates.
src/Aspire.Cli/Templating/CliTemplateFactory.cs Registers the Python starter in CLI template definitions and adds --use-redis-cache option plumbing.
src/Aspire.Cli/Templating/CliTemplateFactory.PythonStarterTemplate.cs Implements the new CLI template application logic, conditional Redis inclusion, and aspire.config.json mutation.
src/Aspire.Cli/Templating/Templates/py-starter/** Adds the new embedded Python starter template content (AppHost + backend + frontend).
src/Aspire.ProjectTemplates/templates/aspire-py-starter/** Deletes the legacy dotnet-template assets for the Python starter.
Files not reviewed (1)
  • src/Aspire.Cli/Templating/Templates/py-starter/package-lock.json: Language not supported

@davidfowl davidfowl force-pushed the davidfowl/python-template-ts branch 2 times, most recently from eb4b0e8 to c190fc3 Compare March 25, 2026 08:23
@github-actions
Copy link
Contributor

Re-running the failed jobs in the CI workflow for this pull request because 2 jobs were identified as retry-safe transient failures in the CI run attempt.
GitHub was asked to rerun all failed jobs for that attempt, and the rerun is being tracked in the rerun attempt.
The job links below point to the failed attempt jobs that matched the retry-safe transient failure rules.

@eerhardt
Copy link
Member

This should use python apphost right? #13947

@davidfowl
Copy link
Contributor Author

This should use python apphost right? #13947

It can, but the app has javascript, python and C#. We're not shipping the python apphost yet. I suspect that will be a bigger move than adding another TS apphost.

@davidfowl
Copy link
Contributor Author

/azp run

@davidfowl davidfowl force-pushed the davidfowl/python-template-ts branch 2 times, most recently from dd71c5a to 7b8fc68 Compare March 26, 2026 04:49
@davidfowl davidfowl force-pushed the davidfowl/python-template-ts branch 4 times, most recently from 778a935 to 9650f92 Compare March 26, 2026 05:54
@davidfowl
Copy link
Contributor Author

Status: Blocked on bundle mode multi-package NuGet restore

The template migration itself is complete and works locally (SDK mode). The E2E test currently only verifies template creation + SDK file generation.

Blocker: Bundle mode (native AOT CLI) doesn't include integration assemblies in the generated TypeScript SDK when aspire.config.json has multiple packages. The aspire-managed nuget restore with multiple --package args produces a libs directory that only contains core Aspire.Hosting — both Aspire.Hosting.JavaScript and Aspire.Hosting.Python are missing.

Evidence from CI workspace capture:

  • Generated aspire.ts has 16K lines but zero integration-specific methods (addUvicornApp, addViteApp, etc.)
  • Single-package restore works fine (TS starter test passes with aspire start/aspire stop)
  • Two-package restore produces SDK with only core functions

Once the bundle mode multi-package restore is fixed, the E2E test should be updated to include aspire run (see comment in PythonReactTemplateTests.cs).

@davidfowl davidfowl force-pushed the davidfowl/python-template-ts branch 3 times, most recently from 8450db4 to 9cb8071 Compare March 26, 2026 13:53
@davidfowl
Copy link
Contributor Author

Status Update

Root cause found: aspire run from workspace root uses the root-level aspire.config.json (which has no packages section) instead of the project-level config. Filed as #15623.

Fix: Aligned the E2E test with the TypeScript starter pattern — cd into the project directory before running aspire start/aspire stop. Also addressed all ConditionalBlockProcessor review feedback from @JamesNK.

Previous status comment about bundle mode multi-package restore is now explained: it was never a NuGet restore bug — the config resolution was reading the wrong file.

@davidfowl
Copy link
Contributor Author

Status Update

Root cause found: aspire run from workspace root uses the root-level aspire.config.json (which has no packages section) instead of the project-level config. Filed as #15623.

Fix: Aligned the E2E test with the TypeScript starter pattern — cd into the project directory before running aspire start/aspire stop. Also addressed all ConditionalBlockProcessor review feedback from JamesNK.

Previous status comment about bundle mode multi-package restore is now explained: it was never a NuGet restore bug — the config resolution was reading the wrong file.

Copy link
Contributor

@maddymontaquila maddymontaquila left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes requested

@github-actions
Copy link
Contributor

Re-running the failed jobs in the CI workflow for this pull request because 1 job was identified as retry-safe transient failures in the CI run attempt.
GitHub was asked to rerun all failed jobs for that attempt, and the rerun is being tracked in the rerun attempt.
The job links below point to the failed attempt jobs that matched the retry-safe transient failure rules.

@davidfowl davidfowl force-pushed the davidfowl/python-template-ts branch 2 times, most recently from eff6bc8 to ad4263e Compare March 27, 2026 06:01
…actory

Migrate the aspire-py-starter template from the legacy DotNetTemplateFactory
(C# AppHost, dotnet new) to the CliTemplateFactory (TypeScript AppHost,
embedded resources). This aligns the Python starter with the existing
TypeScript Express/React starter pattern.

Changes:
- Add py-starter embedded template with TypeScript AppHost using
  addUvicornApp and addViteApp
- Add CliTemplateFactory.PythonStarterTemplate with Redis conditional support
- Add ConditionalBlockProcessor for reusable {{#condition}} block processing
- Remove old template from DotNetTemplateFactory and Aspire.ProjectTemplates
- Install uv in E2E Docker container for Python template support
- Fix AspireStartAsync sed pattern to match both http and https dashboard URLs
- Add workspace and log capture diagnostics for E2E test debugging

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@davidfowl davidfowl force-pushed the davidfowl/python-template-ts branch from ad4263e to 0a5943f Compare March 27, 2026 06:55
@davidfowl davidfowl added the breaking-change Issue or PR that represents a breaking API or functional change over a prerelease. label Mar 27, 2026
@github-actions
Copy link
Contributor

🎬 CLI E2E Test Recordings — 52 recordings uploaded (commit 0a5943f)

View recordings
Test Recording
AddPackageInteractiveWhileAppHostRunningDetached ▶️ View Recording
AddPackageWhileAppHostRunningDetached ▶️ View Recording
AgentCommands_AllHelpOutputs_AreCorrect ▶️ View Recording
AgentInitCommand_DefaultSelection_InstallsSkillOnly ▶️ View Recording
AgentInitCommand_MigratesDeprecatedConfig ▶️ View Recording
AspireAddPackageVersionToDirectoryPackagesProps ▶️ View Recording
AspireUpdateRemovesAppHostPackageVersionFromDirectoryPackagesProps ▶️ View Recording
Banner_DisplayedOnFirstRun ▶️ View Recording
Banner_DisplayedWithExplicitFlag ▶️ View Recording
Banner_NotDisplayedWithNoLogoFlag ▶️ View Recording
CertificatesClean_RemovesCertificates ▶️ View Recording
CertificatesTrust_WithNoCert_CreatesAndTrustsCertificate ▶️ View Recording
CertificatesTrust_WithUntrustedCert_TrustsCertificate ▶️ View Recording
ConfigSetGet_CreatesNestedJsonFormat ▶️ View Recording
CreateAndRunAspireStarterProject ▶️ View Recording
CreateAndRunAspireStarterProjectWithBundle ▶️ View Recording
CreateAndRunEmptyAppHostProject ▶️ View Recording
CreateAndRunJavaEmptyAppHostProject ▶️ View Recording
CreateAndRunJsReactProject ▶️ View Recording
CreateAndRunPythonReactProject ▶️ View Recording
CreateAndRunTypeScriptEmptyAppHostProject ▶️ View Recording
CreateAndRunTypeScriptStarterProject ▶️ View Recording
CreateJavaAppHostWithViteApp ▶️ View Recording
CreateStartAndStopAspireProject ▶️ View Recording
CreateTypeScriptAppHostWithViteApp ▶️ View Recording
DescribeCommandResolvesReplicaNames ▶️ View Recording
DescribeCommandShowsRunningResources ▶️ View Recording
DetachFormatJsonProducesValidJson ▶️ View Recording
DoctorCommand_DetectsDeprecatedAgentConfig ▶️ View Recording
DoctorCommand_WithSslCertDir_ShowsTrusted ▶️ View Recording
DoctorCommand_WithoutSslCertDir_ShowsPartiallyTrusted ▶️ View Recording
GlobalMigration_HandlesCommentsAndTrailingCommas ▶️ View Recording
GlobalMigration_HandlesMalformedLegacyJson ▶️ View Recording
GlobalMigration_PreservesAllValueTypes ▶️ View Recording
GlobalMigration_SkipsWhenNewConfigExists ▶️ View Recording
GlobalSettings_MigratedFromLegacyFormat ▶️ View Recording
InvalidAppHostPathWithComments_IsHealedOnRun ▶️ View Recording
LogsCommandShowsResourceLogs ▶️ View Recording
PsCommandListsRunningAppHost ▶️ View Recording
PsFormatJsonOutputsOnlyJsonToStdout ▶️ View Recording
PublishWithDockerComposeServiceCallbackSucceeds ▶️ View Recording
RestoreGeneratesSdkFiles ▶️ View Recording
RunWithMissingAwaitShowsHelpfulError ▶️ View Recording
SecretCrudOnDotNetAppHost ▶️ View Recording
SecretCrudOnTypeScriptAppHost ▶️ View Recording
StagingChannel_ConfigureAndVerifySettings_ThenSwitchChannels ▶️ View Recording
StopAllAppHostsFromAppHostDirectory ▶️ View Recording
StopAllAppHostsFromUnrelatedDirectory ▶️ View Recording
StopNonInteractiveMultipleAppHostsShowsError ▶️ View Recording
StopNonInteractiveSingleAppHost ▶️ View Recording
StopWithNoRunningAppHostExitsSuccessfully ▶️ View Recording
TypeScriptAppHostWithProjectReferenceIntegration ▶️ View Recording

📹 Recordings uploaded automatically from CI run #23634991048

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking-change Issue or PR that represents a breaking API or functional change over a prerelease.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants